//
// Created by miaomiaole on 2023/5/16.
//

#ifndef CMAKECXX_INITIALIZER_H
#define CMAKECXX_INITIALIZER_H

#include <iostream>

extern int x_1;
extern int y_2;

extern int x_3 ;

class Initializer {
    static int initCount;
public:
    Initializer() {
        std::cout << "Initializer()" << std::endl;
        if (initCount++ == 0) {
            std::cout << "performing initializtion" << std::endl;
            x_1 = 100;
            y_2 = 100;
        }
    }

    ~Initializer() {
        std::cout << "~ Initializer()" << std::endl;
        if (--initCount == 0) {
            std::cout << "performing cleanup " << std::endl;
        }
    }

    int get_x_1() {
        return x_1;
    }

    int get_y_2() {
        return y_2;
    }
};

// 使用静态类 初始化对象，防止全局变量相互依赖导致报错
static Initializer init;

#endif //CMAKECXX_INITIALIZER_H
